/**
 * @Author: mash
 * Date: 2019/8/2 16:42
 */
import Vue from 'vue'
import dialogComponents from "./dialog.vue";

var Dialog = Vue.extend(dialogComponents);


function $alert(content, img) {
    let deffer = null;
    let dialogVm = new Dialog({
        propsData: {
            show: true,
            content,
            img: img ? content : '',
            callback: function (action) {
                if (action) {
                    deffer.resolve && deffer.resolve();
                } else {
                    deffer.reject && deffer.reject();
                }
            }
        }
    });

    let dialogEl = document.createElement("section");
    dialogEl.setAttribute('id', 'xxx')
    document.body.appendChild(dialogEl);
    dialogVm.$mount(dialogEl); //挂载到元素
    return new Promise(((resolve, reject) => {
        deffer = {resolve, reject}
    }))
}

export default {
    install: function (Vue, options) {
        Vue.prototype.$dialog = function (content) {
            return $alert(content)
        }
        Vue.prototype.$imgPreview = function (content) {
            return $alert(content, true)
        }
    }
}